/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.purpose.controller;

import com.koron.purpose.utils.BusinessCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.swan.bean.MessageBean;

import com.koron.common.StaffAttribute;
import com.koron.common.bean.StaffBean;
import com.koron.common.permission.SPIAccountAnno;
import com.koron.purpose.domain.SafetyOrg;
import com.koron.purpose.service.api.SafetyOrgService;
import com.koron.system.annotation.Log;
import com.koron.system.discrete.BusinessManipulation;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

@Api(tags = "safetyOrg", description = "安全机构接口")
@RestController
@RequestMapping("/safetyOrg")
public class SafetyOrgController {

    @Autowired
    private SafetyOrgService service;

    @ApiOperation("删除节点")
    @ApiImplicitParam(name = "id", value = "机构id",  paramType = "query", dataType = "String")
    @RequestMapping(value = "/delete.htm", method = {RequestMethod.POST})
    @Log(title = "删除安全机构节点", businessManipulation = BusinessManipulation.DELETE)
    public MessageBean<?> delete(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.delete(id);
    }

    @ApiOperation("新增")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "机构名称",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "corpCode", value = "公司code",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ranking", value = "排序值",  paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "pid", value = "父id",  paramType = "query", dataType = "String")})
    @RequestMapping(value = "/insert.htm", method = {RequestMethod.POST})
    @Log(title = "新增安全机构节点", businessManipulation = BusinessManipulation.INSERT)
    public MessageBean<?> insert(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, @ApiIgnore SafetyOrg bean) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.insert(bean, user);
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "机构名称", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "ranking", value = "排序值",  paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "id", value = "id", required = true, paramType = "query", dataType = "String")})
    @RequestMapping(value = "/update.htm", method = {RequestMethod.POST})
    @Log(title = "修改安全机构节点", businessManipulation = BusinessManipulation.UPDATE)
    public MessageBean<?> update(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String id, String name, @RequestParam(required = false) Integer ranking) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.update(id, name, ranking, user);
    }

    @ApiOperation("查询")
    @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String")
    @RequestMapping(value = "/query.htm", method = {RequestMethod.GET})
    public MessageBean<?> query(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String corpCode) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.list(corpCode);
    }

    @ApiOperation("树结构")
    @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String")
    @RequestMapping(value = "/tree.htm", method = {RequestMethod.GET})
    public MessageBean<?> tree(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String corpCode) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.tree(corpCode);
    }

    @ApiOperation("树结构")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "corpCode", value = "公司code", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "orgId", value = "机构Id",  paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "staffName", value = "员工名称",  paramType = "query", dataType = "String")
    })
    @RequestMapping(value = "/mobileQuery.htm", method = {RequestMethod.GET})
    public MessageBean<?> mobileQuery(@SPIAccountAnno @StaffAttribute("_user") @ApiIgnore StaffBean user, String corpCode, String orgId, String staffName) {
        if (null == user) {
            MessageBean<?> msg = new MessageBean<>();
            msg.setCode(BusinessCode.NO_LOGIN.getCode());
            msg.setDescription(BusinessCode.NO_LOGIN.getDescription());
            return msg;
        }
        return service.mobileQuery(corpCode,orgId,staffName);
    }

}
